// hdu5307
// 题意：
// 给定n(<=100000)段连续路，每段都对应一个非负长度si，如果选择从第i段到第
// j段将会获得j-i+1愉悦值，现在问如果选择长度和为s(<=50000)的一段路，可能
// 获得的愉悦和是多少？
//
// 题解：
// 可以把前缀和维护出一个多项式f(x)=sigma(i*x^(sum[i]))，然后另一个负数
// 指数的多项式g(x)=sigma((i-1)*x^(-sum[i]))，两个多项式相乘的某一项
// 就对应一段连续的长度和，系数就是答案。
// 处理负数可以加一个偏移量。
//
// run: $exec < bfdiff.in
#include <iostream>
#include <complex>
#include <cmath>
#include <cstring>

int const maxn = 50007 * 4;
int sum[maxn];
long long a[maxn], b[maxn], res[maxn], res1[maxn];
long long ans[maxn];
int n;

namespace fft
{
	using base = std::complex<long double>;
	long double const pi = std::acos(-1);

	int rev[maxn];
	base wlen_pw[maxn];

	void fft(base a[], int n, bool invert)
	{
		for (int i = 0; i < n; i++)
			if (i < rev[i]) std::swap(a[i], a[rev[i]]);

		for (int len = 2; len <= n; len *= 2) {
			long double ang = (2 * pi / len) * (invert ? -1 : 1);
			int len2 = len / 2;
			base wlen(std::cos(ang), std::sin(ang));
			wlen_pw[0] = base(1, 0);
			for (int i = 1; i < len2; i++)
				wlen_pw[i] = wlen_pw[i - 1] * wlen;

			for (int i = 0; i < n; i += len) {
				base t, *pu = a + i, *pv = a + i + len2, *pu_end = a + i + len2, *pw = wlen_pw;
				for (; pu != pu_end; ++pu, ++pv, ++pw) {
					t = *pv * *pw;
					*pv = *pu - t;
					*pu += t;
				}
			}
		}

		if (!invert) return;
		for (int i = 0; i < n; i++) a[i] /= n;
	}

	base fa[maxn], fb[maxn];
	int calc_last = -1;

	void calc_rev(int n)
	{
		if (n == calc_last) return;
		int logn = 0;
		while ((1 << logn) < n) logn++;
		for (int i = 0; i < n; i++) {
			rev[i] = 0;
			for (int j = 0; j < logn; j++)
				if (i & (1 << j))
					rev[i] |= 1 << (logn - j - 1);
		}
		calc_last = n;
	}

	template <class T>
	void multiply(T a[], int n1, T b[], int n2, T res[], int & len)
	{
		int n = 1;
		while (n < n1) n *= 2;
		n *= 2; len = n;
		for (int i = 0; i < n1; i++) fa[i] = a[i];
		for (int i = n1; i < n; i++) fa[i] = 0;
		for (int i = 0; i < n2; i++) fb[i] = b[i];
		for (int i = n2; i < n; i++) fb[i] = 0;

		calc_rev(n);
		fft(fa, n, false); fft(fb, n, false);
		for (int i = 0; i < n; i++) fa[i] *= fb[i];
		fft(fa, n, true);

		for (int i = 0; i < n; i++) res[i] = std::round(fa[i].real());
	}

}

int main()
{
	std::ios_base::sync_with_stdio(false);
	int T; std::cin >> T;
	while (T--) {
		std::cin >> n;
		std::memset(ans, 0, sizeof(ans));
		long long zero_len = 0;
		for (int i = 1; i <= n; i++)  {
			std::cin >> a[i];
			sum[i] = sum[i - 1] + a[i];
			if (a[i]) {
				auto l = zero_len;
				ans[0] += (l + 1) * (l + 1) * l / 2 - l * (l + 1) * (2 * l + 1) / 6;
				zero_len = 0;
			} else zero_len++;
		}
		auto l = zero_len;
		ans[0] += (l + 1) * (l + 1) * l / 2 - l * (l + 1) * (2 * l + 1) / 6;

		std::memset(a, 0, sizeof(a));
		std::memset(b, 0, sizeof(b));
		int s = sum[n];
		for (int i = 0; i <= n; i++) {
			a[sum[i]] += i;
			b[s - sum[i]]++;
		}
		int len;
		fft::multiply(a, s + 1, b, s + s + 2, res, len);

		std::memset(a, 0, sizeof(a));
		std::memset(b, 0, sizeof(b));
		for (int i = 0; i <= n; i++) {
			a[sum[i]]++;
			b[s - sum[i]] -= i;
		}
		fft::multiply(a, s + 1, b, s + s + 2, res1, len);

		for (int i = s; i < std::min(s + s + 1, len); i++)
			ans[i - s] += res[i] + res1[i];

		for (int i = 0; i <= s; i++)
			std::cout << ans[i] << "\n";
	}
}

